home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / term / multitos.trm < prev    next >
Encoding:
Text File  |  1998-12-14  |  9.6 KB  |  402 lines

  1. /*
  2.  * $Id: m 0
  3. TERM_TABLE_EN6 1998/12/14 18:40:36 lhecking Exp $
  4.  */
  5.  
  6. /* GNUPLOT - multitos.trm */
  7.  
  8. /*[
  9.  * Copyright 1994, 1998
  10.  *
  11.  * Permission to use, copy, and distribute this software and its
  12.  * documentation for any purpose with or without fee is hereby granted,
  13.  * provided that the above copyright notice appear in all copies and
  14.  * that both that copyright notice and this permission notice appear
  15.  * in supporting documentation.
  16.  *
  17.  * Permission to modify the software is granted, but not the right to
  18.  * distribute the complete modified source code.  Modifications are to
  19.  * be distributed as patches to the released version.  Permission to
  20.  * distribute binaries produced by compiling modified sources is granted,
  21.  * provided you
  22.  *   1. distribute the corresponding source modifications from the
  23.  *    released version in the form of a patch file along with the binaries,
  24.  *   2. add special version identification to distinguish your version
  25.  *    in addition to the base release version number,
  26.  *   3. provide your name and address as the primary contact for the
  27.  *    support of your modified version, and
  28.  *   4. retain our contact information in regard to use of the base
  29.  *    software.
  30.  * Permission to distribute the released version of the source code along
  31.  * with corresponding source modifications in the form of a patch file is
  32.  * granted with same provisions 2 through 4 for binary distributions.
  33.  *
  34.  * This software is provided "as is" without express or implied warranty
  35.  * to the extent permitted by applicable law.
  36. ]*/
  37.  
  38. /*
  39.  * This file is included by ../term.c.
  40.  *
  41.  * This terminal driver supports:
  42.  *   mtos : ATARI Systems MiNT/MULTITOS/MAGIC with external client
  43.  *
  44.  * AUTHOR
  45.  *  Dirk Stadler (email: dirk_stadler@n.maus.de, dirk@lstm.uni-erlangen.de)
  46.  * 
  47.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  48.  * 
  49.  */
  50.  
  51. #include "driver.h"
  52.  
  53. #ifdef TERM_REGISTER
  54. register_term(mtos)
  55. #endif
  56.  
  57. #ifdef TERM_PROTO
  58.  
  59. /* function-prototypes */
  60. TERM_PUBLIC void MTOS_options(void);
  61. TERM_PUBLIC void MTOS_init(void);
  62. TERM_PUBLIC void MTOS_reset(void);
  63. TERM_PUBLIC void MTOS_graphics(void);
  64. TERM_PUBLIC void MTOS_text(void);
  65. TERM_PUBLIC void MTOS_move(unsigned int x, unsigned int y);
  66. TERM_PUBLIC void MTOS_vector(unsigned int x, unsigned int y);
  67. TERM_PUBLIC void MTOS_linetype(int lt);
  68. TERM_PUBLIC int MTOS_text_angle(int ang);
  69. TERM_PUBLIC void MTOS_put_text(unsigned int x, unsigned int y, char *str);
  70. TERM_PUBLIC int MTOS_justify_text(enum JUSTIFY mode);
  71. TERM_PUBLIC void MTOS_point(unsigned int x, unsigned int y, int number);
  72.  
  73. /* default to ST high resolution */
  74. #define MTOS_XMAX  640
  75. #define MTOS_YMAX  400
  76. #define MTOS_VCHAR 18
  77. #define MTOS_HCHAR 12
  78. #define MTOS_HTIC  5
  79. #define MTOS_VTIC  MTOS_HTIC
  80.  
  81. #define GOT_MTOS_PROTO
  82. #endif /* TERM_PROTO */
  83.  
  84. #ifndef TERM_PROTO_ONLY
  85. #ifdef TERM_BODY
  86.  
  87. #include <unistd.h>
  88. #include <fcntl.h>
  89. #include <param.h>
  90. #include <process.h>
  91. #include <signal.h>
  92. #include <support.h>
  93. #include <sys/stat.h>
  94. #include <time.h>
  95. #include <errno.h>
  96. #include <aesbind.h>
  97. #include <osbind.h>
  98. #include <mintbind.h>
  99.  
  100. int MTOS_pause(char *str);
  101. static void MTOS_quit(void);
  102. void MTOS_open_pipe(void);
  103. static void write_pid(void);
  104. static void init_exit(void);
  105.  
  106. /* commands for GPCLIENT */
  107. #define SET_GRAPHICS    'G'
  108. #define SET_TEXT        'E'
  109. #define SET_LINE        'L'
  110. #define SET_ANGLE       'A'
  111. #define SET_JUSTIFY     'J'
  112. #define SET_POINTMODE   'D'
  113. #define GR_MOVE         'M'
  114. #define GR_DRAW         'V'
  115. #define GR_RESET        'R'
  116. #define GR_TEXT         'T'
  117.  
  118. #define PAUSE           'P'
  119. #define PID             'I'
  120. #define QUIT            'Q'
  121.  
  122. /* for creating pipes */
  123. #define PIPE1           "u:\\pipe\\GPLT%d"
  124. #define PIPE2           "u:\\pipe\\gpclient.tmp"
  125. #define NAMESIZE        25
  126. #define SIZE            ((unsigned)sizeof(short))
  127.  
  128. /* default name for client */
  129. #define GPCLIENT1       "gpclient.prg"
  130. #define GPCLIENT2       "gpclient"
  131.  
  132. /* environment */
  133. #define MYENV          "GNUPLOTPATH"
  134. #define PATH           "PATH"
  135.  
  136. /* some global variables */
  137. static char MTOS_mode = 0;
  138. static int handle = -1;
  139. static int pid = -1;
  140.  
  141. TERM_PUBLIC void MTOS_options()
  142. {
  143.     term_options[0] = NUL;
  144. }
  145.  
  146. TERM_PUBLIC void MTOS_init()
  147. {
  148.     char pipe[NAMESIZE];
  149.     char *file, cmd[MAXPATHLEN+1];
  150.     char const *const ext[] = { "prg", "app", NULL };
  151.  
  152.     if (handle < 0) {
  153.     if (aesid < 0) {
  154.         if ((aesid = appl_init()) < 0)
  155.         int_error("APPL_INIT failed !", NO_CARET);
  156.     }
  157.     file = findfile(GPCLIENT2, getenv(MYENV), ext);
  158.     if (!file)
  159.         safe_strncpy(cmd, GPCLIENT1, sizeof(cmd));
  160.     else if (file && !strchr(file, '\\') && !strchr(file, '/'))
  161.         safe_strncpy(cmd, file, sizeof(cmd));
  162.     else
  163.         unx2dos(file, cmd);
  164.     if (!shel_find(cmd))
  165.         int_error("Cannot find GPCLIENT !", NO_CARET);
  166.  
  167.     sprintf(&pipe[1], PIPE1, aesid);
  168.  
  169.     if ((handle = open(&pipe[1], O_RDWR | O_CREAT)) < 0) {
  170.         if ((handle = (int) Fcreate(&pipe[1], 0)) < 0)
  171.         int_error("Cannot open PIPE to GPCLIENT !", NO_CARET);
  172.     }
  173.     pipe[0] = (char) (strlen(&pipe[1]) + 1);
  174.  
  175.     if (!shel_write(1, 1, 100, cmd, pipe)) {
  176.         close(handle);
  177.         handle = -1;
  178.         int_error("Cannot spawn GPCLIENT !", NO_CARET);
  179.     }
  180.     init_exit();
  181.     }
  182.     if (aesid > -1)
  183.     menu_register(aesid, "  Terminal: mtos");
  184. }
  185.  
  186. TERM_PUBLIC void MTOS_reset()
  187. {
  188.     short buff;
  189.  
  190.     buff = (short) GR_RESET;
  191.     write(handle, &buff, SIZE);
  192. }
  193.  
  194. TERM_PUBLIC void MTOS_text()
  195. {
  196.     short buff;
  197.  
  198.     buff = (short) SET_TEXT;
  199.     if (MTOS_mode != SET_TEXT)
  200.     write(handle, &buff, SIZE);
  201.     MTOS_mode = SET_TEXT;
  202. }
  203.  
  204. TERM_PUBLIC void MTOS_graphics()
  205. {
  206.     short buff;
  207.  
  208.     buff = (short) SET_GRAPHICS;
  209.     write(handle, &buff, SIZE);
  210.     MTOS_mode = SET_GRAPHICS;
  211. }
  212.  
  213. TERM_PUBLIC void MTOS_move(unsigned int x, unsigned int y)
  214. {
  215.     short x_1, y_1, buff;
  216.  
  217.     x_1 = (short) x;
  218.     y_1 = (short) y;
  219.     buff = (short) GR_MOVE;
  220.     write(handle, &buff, SIZE);
  221.     write(handle, &x_1, SIZE);
  222.     write(handle, &y_1, SIZE);
  223. }
  224.  
  225. TERM_PUBLIC void MTOS_vector(unsigned int x, unsigned int y)
  226. {
  227.     short x_1, y_1, buff;
  228.  
  229.     x_1 = (short) x;
  230.     y_1 = (short) y;
  231.     buff = (short) GR_DRAW;
  232.     write(handle, &buff, SIZE);
  233.     write(handle, &x_1, SIZE);
  234.     write(handle, &y_1, SIZE);
  235. }
  236.  
  237. TERM_PUBLIC void MTOS_linetype(int lt)
  238. {
  239.     short lt_1, buff;
  240.  
  241.     lt_1 = (short) lt;
  242.     buff = (short) SET_LINE;
  243.     write(handle, &buff, SIZE);
  244.     write(handle, <_1, SIZE);
  245. }
  246.  
  247. TERM_PUBLIC int MTOS_text_angle(int ang)
  248. {
  249.     short ta_1, buff;
  250.  
  251.     ta_1 = (short) ang;
  252.     buff = (short) SET_ANGLE;
  253.     write(handle, &buff, SIZE);
  254.     write(handle, &ta_1, SIZE);
  255.     return (TRUE);
  256. }
  257.  
  258. TERM_PUBLIC void MTOS_put_text(unsigned int x, unsigned int y, char *str)
  259. {
  260.     short x_1, y_1, len, buff;
  261.  
  262.     x_1 = (short) x;
  263.     y_1 = (short) y;
  264.     len = (short) strlen(str) + 1;
  265.     buff = (short) GR_TEXT;
  266.     write(handle, &buff, SIZE);
  267.     write(handle, &x_1, SIZE);
  268.     write(handle, &y_1, SIZE);
  269.     write(handle, &len, SIZE);
  270.     write(handle, str, (unsigned) len);
  271. }
  272.  
  273. TERM_PUBLIC int MTOS_justify_text(enum JUSTIFY mode)
  274. {
  275.     short j_mode, buff;
  276.  
  277.     j_mode = (short) mode;
  278.     buff = (short) SET_JUSTIFY;
  279.     write(handle, &buff, SIZE);
  280.     write(handle, &j_mode, SIZE);
  281.     return (TRUE);
  282. }
  283.  
  284. TERM_PUBLIC void MTOS_point(unsigned int x, unsigned int y, int number)
  285. {
  286.     short mode, buff;
  287.  
  288.     buff = (short) SET_POINTMODE;
  289.     mode = 1;
  290.     write(handle, &buff, SIZE);
  291.     write(handle, &mode, SIZE);
  292.     do_point(x, y, number);
  293.     mode = 0;
  294.     write(handle, &buff, SIZE);
  295.     write(handle, &mode, SIZE);
  296. }
  297.  
  298. int MTOS_pause(char *str)
  299. {
  300.     short len, buff;
  301.  
  302.     len = (short) strlen(str) + 1;
  303.     buff = (short) PAUSE;
  304.     write(handle, &buff, SIZE);
  305.     write(handle, &len, SIZE);
  306.     write(handle, str, (unsigned) len);
  307.     read(handle, &len, SIZE);
  308.     return ((int) len);
  309. }
  310.  
  311. static void MTOS_quit()
  312. {
  313.     short buff;
  314.  
  315.     if (pid > -1)
  316.     kill(pid, SIGTERM);
  317.     if (handle > -1) {
  318.     buff = (short) QUIT;
  319.     write(handle, &buff, SIZE);
  320.     close(handle);
  321.     }
  322. }
  323.  
  324. void MTOS_open_pipe()
  325. {
  326.     char pipe[NAMESIZE];
  327.     short len;
  328.  
  329.     if (handle < 0) {
  330.     if ((handle = open(PIPE2, O_RDWR)) < 0)
  331.         return;
  332.     read(handle, &len, SIZE);
  333.     if (len > 0) {
  334.         read(handle, pipe, (unsigned) len);
  335.         close(handle);
  336.         if ((handle = open(pipe, O_RDWR)) < 0) {
  337.         fprintf(stderr, "\n\n\33p Can't open Pipe: (%s) Error: (%s) !\33q\n\n", pipe,sys_errlist[errno]);
  338.         fflush(stderr);
  339.         return;
  340.         }
  341.     }
  342.     init_exit();
  343.     }
  344. }
  345.  
  346. static void write_pid()
  347. {
  348.     short buff, mypid, gpclpid;
  349.  
  350.     mypid = (short) getpid();
  351.     buff = (short) PID;
  352.     while (write(handle, &buff, SIZE) <= 0)
  353.     Fselect(100, 0L, 0L, 0L);
  354.     while (read(handle, &gpclpid, SIZE) <= 0)
  355.     Fselect(100, 0L, 0L, 0L);
  356.     write(handle, &mypid, SIZE);
  357.     pid = (int) gpclpid;
  358. }
  359.  
  360. static void init_exit()
  361. {
  362.     Cconout(7);
  363.     write_pid();
  364.     atexit(MTOS_quit);
  365. }
  366.  
  367. #endif /* TERM_BODY */
  368.  
  369. #ifdef TERM_TABLE
  370.  
  371. TERM_TABLE_START(mtos_driver)
  372.     "mtos", "Atari MiNT/MULTITOS/Magic Terminal",
  373.     MTOS_XMAX, MTOS_YMAX, MTOS_VCHAR, MTOS_HCHAR,
  374.     MTOS_VTIC, MTOS_HTIC, MTOS_options, MTOS_init, MTOS_reset,
  375.     MTOS_text, null_scale, MTOS_graphics, MTOS_move, MTOS_vector,
  376.     MTOS_linetype, MTOS_put_text, MTOS_text_angle,
  377.     MTOS_justify_text, MTOS_point, do_arrow, set_font_null,
  378.     0, TERM_CAN_MULTIPLOT, 0, 0
  379. TERM_TABLE_END(mtos_driver)
  380.  
  381. #undef LAST_TERM
  382. #define LAST_TERM mtos_driver
  383.  
  384. #endif /* TERM_TABLE */
  385.  
  386. #endif /* TERM_PROTO_ONLY */
  387.  
  388. #ifdef TERM_HELP
  389. START_HELP(mtos)
  390. "1 mtos",
  391. "?commands set terminal mtos",
  392. "?set terminal mtos",
  393. "?set term mtos",
  394. "?terminal mtos",
  395. "?term mtos",
  396. "?mtos",
  397. " The `mtos` terminal has no options.  It sends data via a pipe to an external",
  398. " program called GPCLIENT.  It runs under MULTITOS, Magic 3.x, MagicMAC. and",
  399. " MiNT.  If you cannot find GPCLIENT, than mail to dirk@lstm.uni-erlangen.de."
  400. END_HELP(mtos)
  401. #endif /* TERM_HELP */
  402.